package com.bang.study.esl.listener;


import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.freeswitch.esl.client.inbound.IEslEventListener;
import org.freeswitch.esl.client.internal.Context;
import org.freeswitch.esl.client.transport.event.EslEvent;
import org.freeswitch.esl.client.transport.message.EslHeaders;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @Auther:
 * @Date: 2019-05-16 15:05
 * @Description: 类描述
 */
@Component
@Slf4j
public class EslEventListener implements IEslEventListener {

    /**
     * Signal of a server initiated event.
     *
     * @param ctx
     * @param eslEvent as an {@link EslEvent}
     */
    @Override
    public void onEslEvent(Context ctx, EslEvent eslEvent) {
//        String eventDateGmt = eslEvent.getEventDateGmt();
//        String eventDateLocal = eslEvent.getEventDateLocal();
//        long eventDateTimestamp = eslEvent.getEventDateTimestamp();
//        log.error("eventDateGmt: {}", eventDateGmt);
//        log.error("eventDateLocal: {}", eventDateLocal);
//        log.error("eventDateTimestamp: {}", eventDateTimestamp);
//
//        String eventName = eslEvent.getEventName();
//        log.error("eventName: {}", eventName);
//
//        List<String> eventBodyLines = eslEvent.getEventBodyLines();
//        log.error("eventBodyLines: {}", JSONObject.toJSONString(eventBodyLines));
//
//        Map<String, String> eventHeaders = eslEvent.getEventHeaders();
//        log.error("eventHeaders: {}", JSONObject.toJSONString(eventHeaders));
//
//        Map<EslHeaders.Name, String> messageHeaders = eslEvent.getMessageHeaders();
//        log.error("eventBodyLines: {}", JSONObject.toJSONString(messageHeaders));
//        log.error("=============== eventReceived");
//
//        String variable_helloworld = eventHeaders.get("variable_HELLOWORLD");
//        System.out.println(variable_helloworld);
    }
}